import GameManager from "../Managers/GameManager";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Wood extends cc.Component {

    interval:number;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {
        this.WoodFall();
    }

    // update (dt) {}

    WoodFall(){
        this.interval = setInterval(()=>{
            if(!this.node.getComponent(cc.RevoluteJoint) && this.node.y < -1000) {
                var num = GameManager.Instance.woodArr.indexOf(this.node);
                GameManager.Instance.SpliceWoodArr(num, 1);
                clearInterval(this.interval);
                this.node.active = false;
            }
        }, 1000);
    }

    protected onDestroy(): void {
        clearInterval(this.interval);
    }
}
